package com.yxdj.service.controller;

import com.yxdj.common.core.web.controller.BaseController;
import com.yxdj.common.core.web.domain.AjaxResult;
import com.yxdj.common.core.web.page.TableDataInfo;
import com.yxdj.common.log.annotation.Log;
import com.yxdj.common.log.enums.BusinessType;
import com.yxdj.common.security.annotation.RequiresPermissions;
import com.yxdj.service.api.domain.ServiceItem;
import com.yxdj.service.service.ServiceItemService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 服务项管理
 */
@Tag(name = "服务项管理")
@RestController
@RequestMapping("/item")
public class ServiceItemController extends BaseController {

    @Autowired
    private ServiceItemService serviceItemService;

    @Operation(summary = "查询所有服务项")
    @GetMapping("/all")
    public AjaxResult getAll() {
        return success(serviceItemService.list());
    }

    /**
     * 分页获取服务项列表
     */
    @Operation(summary = "分页获取服务项列表")
    @GetMapping("/list")
    public TableDataInfo list(ServiceItem serviceItem) {
        startPage();
        List<ServiceItem> list = serviceItemService.getPageList(serviceItem);
        return getDataTable(list);
    }

    /**
     * 获取服务项详细信息
     */
    @Operation(summary = "获取服务项详细信息")
    @GetMapping(value = "/getById/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return success(serviceItemService.getById(id));
    }

    /**
     * 新增服务项
     */
    @Operation(summary = "新增服务项")
    @Log(title = "服务项管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServiceItem serviceItem) {
        return toAjax(serviceItemService.save(serviceItem));
    }

    /**
     * 修改服务项
     */
    @Operation(summary = "修改服务项")
    @Log(title = "服务项管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServiceItem serviceItem) {
        return toAjax(serviceItemService.updateById(serviceItem));
    }

    /**
     * 删除服务项
     */
    @Operation(summary = "删除服务项")
    @RequiresPermissions("system:serviceItem:remove")
    @Log(title = "服务项管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        return toAjax(serviceItemService.removeByIds(ids));
    }

}
